<template>
  <a-modal v-model="visible" title="请输入登录密码" @ok="onSubmit">
    <a-form-model
      ref="ruleForm"
      :model="form"
      :rules="rules"
      :label-col="{ span: 4 }"
      :wrapper-col="{ span: 14 }"
    >
      <a-form-model-item label="密码" prop="password">
        <a-input type="password" v-model="form.password" />
      </a-form-model-item>
    </a-form-model>
  </a-modal>
</template>
<script>
export default {
  data() {
    return {
      visible: false,
      form: {
        password: '',
      },
      rules: {
        password: [
          {
            required: true,
            message: '请输入',
            trigger: 'blur',
          },
        ],
      },
    }
  },
  methods: {
    open() {
      this.visible = true
    },
    onSubmit() {
      this.$refs.ruleForm.validate((valid) => {
        if (valid) {
          this.axios.post('/s/password/check', this.form).then((res) => {
            if (res.data.code === 1) {
              this.visible = false
              this.form.password = ''
              this.$emit('password-checked')
              this.$message.success('登录密码验证通过')
              return
            }
            this.$message.error(res.data.msg)
          })
        }
      })
    },
  },
}
</script>
